package com.ruoyi.basedata.service.impl;

import com.ruoyi.basedata.domain.Replace;
import com.ruoyi.basedata.mapper.ReplaceMapper;
import com.ruoyi.basedata.service.IReplaceService;
import com.ruoyi.common.constant.Constants;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Objects;

/**
 * 换记录Service业务层处理
 *
 * @author ruoyi
 * @date 2023-09-07
 */
@Service
public class ReplaceServiceImpl implements IReplaceService
{
    @Autowired
    private ReplaceMapper replaceMapper;

    /**
     * 查询换记录
     *
     * @param ID 换记录主键
     * @return 换记录
     */
    @Override
    public Replace selectReplaceByID(Long ID)
    {
        return replaceMapper.selectReplaceByID(ID);
    }

    /**
     * 查询换记录列表
     *
     * @param replace 换记录
     * @return 换记录
     */
    @Override
    public List<Replace> selectReplaceList(Replace replace)
    {
        SysUser user = SecurityUtils.getLoginUser().getUser();
        if (!Objects.equals(user.getSystemFlag(), Constants.SYS_FLAG_ADMIN)) {
            Long userId = user.getUserId();
            replace.setLoginUserId(userId.intValue());
        }
        if (Objects.equals(user.getSystemFlag(), Constants.SYS_FLAG_NORMAL_USER)) {
            replace.setTenantId(user.getTenantId());
        }
        return replaceMapper.selectReplaceList(replace);
    }

    /**
     * 新增换记录
     *
     * @param replace 换记录
     * @return 结果
     */
    @Override
    public int insertReplace(Replace replace)
    {
        return replaceMapper.insertReplace(replace);
    }

    /**
     * 修改换记录
     *
     * @param replace 换记录
     * @return 结果
     */
    @Override
    public int updateReplace(Replace replace)
    {
        return replaceMapper.updateReplace(replace);
    }

    /**
     * 批量删除换记录
     *
     * @param IDs 需要删除的换记录主键
     * @return 结果
     */
    @Override
    public int deleteReplaceByIDs(Long[] IDs)
    {
        return replaceMapper.deleteReplaceByIDs(IDs);
    }

    /**
     * 删除换记录信息
     *
     * @param ID 换记录主键
     * @return 结果
     */
    @Override
    public int deleteReplaceByID(Long ID)
    {
        return replaceMapper.deleteReplaceByID(ID);
    }

    @Override
    public List<Replace> selectList(Replace replace) {

        SysUser user = SecurityUtils.getLoginUser().getUser();
        if (!Objects.equals(user.getSystemFlag(), Constants.SYS_FLAG_ADMIN)) {
            Long userId = user.getUserId();
            replace.setLoginUserId(userId.intValue());
        }
        if (Objects.equals(user.getSystemFlag(), Constants.SYS_FLAG_NORMAL_USER)) {
            replace.setTenantId(user.getTenantId());
        }
        return replaceMapper.selectList(replace);
    }
}
